package com.example.task1.ui.AllService.volunteer;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.base.BaseActivity;
import com.example.task1.bean.VolunteerMyBean;
import com.example.task1.http.Api;
import com.example.task1.util.ApiResp;
import com.example.task1.util.CallBack;

import retrofit2.Call;

public class VolunteerMyActivity extends BaseActivity {

    private RecyclerView rvList;
    private VolunteerMyAdapter volunteerMyAdapter;
    private TextView end;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_volunteer_my);
        initView();
        initData();
        volunteerMyAdapter = new VolunteerMyAdapter(this);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        rvList.setLayoutManager(linearLayoutManager);
        rvList.setAdapter(volunteerMyAdapter);
    }

    public void initData() {
        Call<ApiResp> call = Api.api().get(MyApplication.TOKEN, "/prod-api/api/volunteer-service/activity/my-list/1");
        Api.send(call, VolunteerMyBean.class, new CallBack<VolunteerMyBean>() {
            @Override
            public void success(VolunteerMyBean data) {
                if (data.getRows().size() < 1) {
                    end.setVisibility(View.VISIBLE);
                } else {
                    end.setVisibility(View.GONE);
                    volunteerMyAdapter.setData(data.getRows());
                }
            }

            @Override
            public void error(String msg) {

            }
        });
    }

    @Override
    public String getMyTitle() {
        return "我报名的活动";
    }

    private void initView() {
        rvList = findViewById(R.id.rv_list);
        end = findViewById(R.id.end);
    }
}